<template>
	<view>
			<my-search @click="gotoSearch"></my-search>
		<!-- 轮播图 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			<!-- for 循环 -->
			<swiper-item v-for="(item,index) in swiperList" :key="index">
				<!-- view 换成navigator -->
				<navigator class="swiper-item" :url="`/subpkg/goods_detail/goods_detail?goods_id=${item.goods_id}`">
					<image :src="item.image_src" />
				</navigator>
			</swiper-item>
		</swiper>
		<!-- 分类导航区域 -->
		<view class="nav-box">
			<!-- 绑定点击事件 -->
			<view class="nav-item" v-for="(item,index) in navList" :key="index" @click="navClickHandler(item)">
				<image :src="item.image_src" />
			</view>
		</view>
		<!-- 楼层区域 -->
		<view class="floor-list">
			<view class="floor-item" v-for="(item,index) in floorList" :key="index">
				<image class="floor-title" :src="item.floor_title.image_src"></image>
				<!-- 楼层图片区域 -->
				<view class="floor-img-box">
					<!-- 左边 -->
					<navigator :url="item.product_list[0].url" class="left-img-box">
						<image mode="widthFix" :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width+'rpx'}"></image>
					</navigator>
					<!-- 右边 -->
					<view class="right-img-box">
						<navigator :url="item2.url" v-if="index2 !== 0" class="right-img-item" v-for='(item2,index2) in item.product_list' :key="index2">
							<image :style="{width:item2.image_width+'rpx'}" :src="item2.image_src" mode="widthFix"></image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import badgeMixin from '@/mixins/tabber-badge.js'
	export default {
		mixins:[badgeMixin],
		data() {
			return {
				// 轮播图数据存放
				swiperList:[],
				// 分类导航区域
				navList:[],
				floorList:[],
			};
		},
		// 页面加载时触发
		onLoad(){
			this.getSwiperData(),
			this.getNavData(),
			this.getFloorList()
		},
		methods:{
			// 获取轮播图接口
			async getSwiperData(){
			   const {data:res} = await uni.$http.get('/api/public/v1/home/swiperdata')
				// 判断状态码
				if(res.meta.status !== 200) return uni.$showMsg()
				this.swiperList = res.message
			},
			// 获取分类导航数据
			async getNavData(){
				const {data:res} = await uni.$http.get('/api/public/v1/home/catitems')
				if(res.meta.status !== 200) return uni.$showMsg()
				this.navList = res.message
			},
			// 分类导航点击跳转
			navClickHandler(item){
				if(item.name === '分类') {
					uni.switchTab({
						url:"/pages/cate/cate"
					})
				}
			},
			// 获取楼层数据
			async getFloorList(){
				const {data:res} = await uni.$http.get('/api/public/v1/home/floordata')
				if(res.meta.status !== 200) return uni.$showMsg()
				// 操作数据
				res.message.forEach(item=>{
					item.product_list.forEach(prod=>{
						prod.url = '/subpkg/goods_list/goods_list?'+prod.navigator_url.split('?')[1]
					})
				})
				this.floorList = res.message
				console.log(this.floorList);
			},
			gotoSearch(){
				uni.navigateTo({
					url:'/subpkg/search/search'
				})
			}
		}
	}
</script>

<style lang="scss">
swiper {
	height: 330rpx;
	.swiper-item,image {
		width: 100%;
		height: 100%;
	}
}
.nav-box {
	display: flex;
	justify-content: space-around;
	margin: 15px 0;
	image {
		width: 128rpx;
		height: 140rpx;	
	}
}
.floor-title {
	height: 60rpx;
	width: 100%;
	display: flex;
}
.right-img-box {
	display: flex;
	flex-wrap: wrap;
	
	justify-content: space-around;
}
.floor-img-box {
	display: flex;
	padding-left: 10rpx;
}
</style>
